﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using SUMO.MediaBrowser.ViewModel;

namespace SUMO.MediaBrowser.Controls
{
    /// <summary>
    /// Presents a list of children within a hierarchical media item (ie: a folder or other metadata) and 
    /// offers abilites to add new items, or edit existing items. DataContext should always be set with an 
    /// object of type HierarchicalMediaItem.
    /// </summary>
    public partial class MediaImageList : UserControl
    {
        public MediaImageList()
        {
            InitializeComponent();
            SetBinding(MyDataContextProperty, new Binding());
        }

        #region DataContext change notification
        public static readonly DependencyProperty MyDataContextProperty =
                DependencyProperty.Register("MyDataContext",
                                    typeof(Object),
                                    typeof(MediaImageList),
                                    new PropertyMetadata(DataContextChanged));

        private static void DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            MediaImageList myControl = (MediaImageList)sender;
            INotifyPropertyChanged dataContextItem = e.NewValue as INotifyPropertyChanged;
            if (dataContextItem != null)
            {
                var dataContextModel = dataContextItem as HierarchicalMediaItem;
                if (dataContextModel != null)
                {
                    myControl.MediaList.ItemsSource = dataContextModel.ChildItems;
                }
            }
        }
        #endregion DataContext change notification

        private void MediaList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                var selectedDataItem = MediaList.SelectedItem as HierarchicalMediaItem;
            }
        }
    }
}
